#pragma once
#include "DHeightfield.h"
#include "../DSpace.h"
#include "DHeightfieldData.h"

namespace Skill
{
	namespace Ode
	{
		namespace Geometries
		{		
			void DHeightfield::CollectManagedMemory()
			{
				_Data = nullptr;				
				DGeometry::CollectManagedMemory();
			}
			DHeightfield::DHeightfield(DSpace^ space, DHeightfieldData^ data, bool placeable) 
				:DGeometry(space)
			{
				dSpaceID s = space?space->_Space() : NULL;
				_SetPointer(dCreateHeightfield( s,data->_This, placeable? 1 : 0 ),true);
				_Data = data;	
				if(_Container)
						_Container->AddSpace(this);
			}
			DHeightfieldData^ DHeightfield::Data::get()
			{
				if(IsSpace) return nullptr;
				return _Data;
			}
			void DHeightfield::Data::set(DHeightfieldData^ value)
			{
				if(IsSpace) return;
				_Data = value;
				if(_Data)
					dGeomHeightfieldSetHeightfieldData(_Geom(),_Data->_This);
				else
					dGeomHeightfieldSetHeightfieldData(_Geom(),NULL);
			}					
		}
	}
}